package main.java.game.item;

import main.java.game.Player;
import main.java.game.combatant.Combatant;
import main.java.game.combatant.Hero;


public class Armour extends AffordableEquipable{

	private Integer defense;
	private Integer init;
	
	
	public Armour(String name, Integer defenseValue, Integer initValue,Integer buyingPrice, ArmourType type){
		super(name, defenseValue,0,initValue,buyingPrice);
		this.setType(type);
		
		
	}
	private ArmourType type;
	
	private Player player;
	public Player getPlayer() {
		return player;
	}
	public void setPlayer(Player player) {
		this.player = player;
	}

	public Integer getInit(){
		return init;
	}
	public Integer getDefense(){
		return defense;
	}
	
	public void equip(Combatant hero){
			hero.setDefense(hero.getDefense()+defense);
			hero.setInit(hero.getInit()+init);
	}
	

	public void equip(Hero h) {
		if(h.getArmour()!=null)
			this.unequip(h);
		Player p=h.getPlayer();
		h.setInit(h.getInit()+getInitValue());
		h.setAttack(h.getAttack()+getAttackValue());
		h.setDefense(h.getDefense()+getDefValue());
		h.setArmour(this);
		p.removeArmour(this);
		
	}

	@Override
	public void unequip(Hero h) {
		Armour a=h.getArmour();
		Player p=h.getPlayer();
		p.getArmours().add(a);
		h.setInit(h.getInit()-getInitValue());
		h.setAttack(h.getAttack()-getAttackValue());
		h.setDefense(h.getDefense()-getDefValue());
		h.setArmour(null);
	}
	public void setType(ArmourType type) {
		this.type = type;
	}
	public ArmourType getType() {
		return type;
	}

}
